home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRNOMY / AA_51.ZIP / ANGLES.C < prev    next >
C/C++ Source or Header  |  1993-02-09  |  1KB  |  51 lines

  1.  
  2. /* Sun - object - earth angles and distances.
  3.  * q (object), e (earth), and p (q minus e) are input vectors.
  4.  * The answers are posted in the following global locations:
  5.  */
  6.  
  7. double SE = 0.0;    /* earth-sun distance */
  8. double SO = 0.0;    /* object-sun distance */
  9. double EO = 0.0;    /* object-earth distance */
  10.  
  11. double pq = 0.0;    /* cosine of sun-object-earth angle */
  12. double ep = 0.0;    /* -cosine of sun-earth-object angle */
  13. double qe = 0.0;    /* cosine of earth-sun-object angle */
  14.  
  15. #include "kep.h"
  16.  
  17.  
  18. int angles( p, q, e )
  19. double p[], q[], e[];
  20. {
  21. double a, b, s;
  22. int i;
  23.  
  24. EO = 0.0;
  25. SE = 0.0;
  26. SO = 0.0;
  27. pq = 0.0;
  28. ep = 0.0;
  29. qe = 0.0;
  30. for( i=0; i<3; i++ )
  31.     {
  32.     a = e[i];
  33.     b = q[i];
  34.     s = p[i];
  35.     EO += s * s;
  36.     SE += a * a;
  37.     SO += b * b;
  38.     pq += s * b;
  39.     ep += a * s;
  40.     qe += b * a;
  41.     }
  42. EO = sqrt(EO); /* Distance between Earth and object */
  43. SO = sqrt(SO); /* Sun - object */
  44. SE = sqrt(SE); /* Sun - earth */
  45. pq /= EO*SO;    /* cosine of sun-object-earth */
  46. ep /= SE*EO;    /* -cosine of sun-earth-object */
  47. qe /= SO*SE;    /* cosine of earth-sun-object */
  48. return(0);
  49. }
  50.  
  51.